package com.kuhyygy.sqlite.dao;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;

/**
 * DB的工具类
 *     提供一个对数据库的操作类,主要用到SQLiteOpenHelper里的getWritableDatabase
 * 方法
 * @author KuhYygy
 * @since 2013-03-16
 */
public class DBHelper extends SQLiteOpenHelper {
	
	private static final String TAG = "DBHelper";
	
	private static String DB_NAME = "data.db";
	private static int VERSION = 3;

	public DBHelper(Context context) {
		super(context, DB_NAME, null, VERSION);
	}

	@Override
	public void onCreate(SQLiteDatabase db) {
		db.execSQL("create table t_person (_id integer primary key, name varchar(20), gender varchar(20))");
		db.execSQL("insert into t_person (name, gender) values ('小陈', '男')");
		db.execSQL("insert into t_person (name, gender) values ('大fat', '女')");
		db.execSQL("insert into t_person (name, gender) values ('麻吱', '女')");
		db.execSQL("insert into t_person (name, gender) values ('嗯嘿你', '男')");
		db.execSQL("insert into t_person (name, gender) values ('吱哩哩哩哩', '男')");
		Log.i(TAG, "-------初始化数据库信息,创建了表 t_person-------");
	}

	@Override
	public void onUpgrade(SQLiteDatabase db, int arg1, int arg2) {
		Log.i(TAG, "Update Database");
		db.execSQL("create table t_student (id integer primary key, name varchar(20), age integer)");
	}

}
